/*
 * PopupSubmitCanvassMsg.cpp
 *
 *  Created on: Jul 16, 2012
 *      Author: guillou
 */

#include "PopupCanvassSubmitMsg.hpp"

using namespace std;
using namespace Popup;

CanvassSubmitMsg::CanvassSubmitMsg(const Message *p_message)
: AbstractMessage(POPUP_MSG_TYPE_CANVASS_SUBMIT)
{
  AbstractMessage::deserialize(p_message);
}

bool CanvassSubmitMsg::onSend()
{
  bool _rc = payloadAddLongLong(ID, canvass.canvassID);

  if (_rc) {
    _rc = payloadAddLong(TARGETS, canvass.targets);
  }
  if (_rc) {
    payloadAddLong(SENDER, canvass.senderID);
  }
  if (_rc) {
    payloadAddString(QUESTION, canvass.question);
  }
  if (_rc) {
    payloadAddString(CHOICES, canvass.choices);
  }
  if (_rc) {
    payloadAddShort(TIMEOUT, canvass.timeout);
  }
  if (_rc) {
    payloadAddBoolean(ANONYMOUS, canvass.isAnonymous);
  }
  if (_rc) {
    payloadAddBoolean(ALLOW_MULTISELECTION, canvass.allowMultiSelection);
  }

  return _rc;
}

bool CanvassSubmitMsg::onReceive()
{
  bool _rc = payloadGetLongLong(ID, canvassID);

  if (_rc) {
    _rc = payloadGetLong(TARGETS, targets);
  }
  if (_rc) {
    _rc = payloadGetLong(SENDER, senderID);
  }
  if (_rc) {
    payloadGetString(QUESTION, question);
  }
  if (_rc) {
    payloadGetString(CHOICES, choices);
  }
  if (_rc) {
    payloadGetShort(TIMEOUT, timeout);
  }
  if (_rc) {
    payloadGetBoolean(ANONYMOUS, isAnonymous);
  }
  if (_rc) {
    payloadGetBoolean(ALLOW_MULTISELECTION, allowMultiSelection);
  }
  return _rc;
}
